//
//  RootViewController.m
//  Service4U
//
//  Created by Hai Nguyen on 10/5/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "RootViewController.h"
#import "HomeViewController.h"
#import "DirectionViewController.h"
#import "AppointmentViewController.h"

@implementation RootViewController
@synthesize tabBarView;
@synthesize navigationController;
@synthesize homeViewController;
@synthesize directionViewcontroller;
@synthesize appointmentViewController;

#pragma mark -
#pragma mark S4UTabBarView Delegate

- (void)pressedButtonWithTag:(int) tag{
	switch (tag) {
		case KHomeButtonTag:
			[self.navigationController popToRootViewControllerAnimated:YES];
			break;
		case KMapButtonTag:
			[self.navigationController popToRootViewControllerAnimated:NO];
			[self.navigationController pushViewController:directionViewcontroller animated:YES];
			break;
		case KAppointmentButtonTag:
			[self.navigationController popToRootViewControllerAnimated:NO];
			[self.navigationController pushViewController:appointmentViewController animated:YES];
			break;
	}
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	tabBarView = [[[NSBundle mainBundle] loadNibNamed:@"S4UTabBarView" owner:self options:nil] lastObject];
	[self.view addSubview:tabBarView];
	[tabBarView setFrame:CGRectMake(0, self.view.frame.size.height - tabBarView.frame.size.height, self.view.frame.size.width, tabBarView.frame.size.height)];
	tabBarView.viewDelegate = self;
	[self.view addSubview:navigationController.view];
	[navigationController.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height-tabBarView.frame.size.height)];
	homeViewController = [[HomeViewController alloc] init];
	homeViewController.tabBarViewController = tabBarView;
	directionViewcontroller = [[DirectionViewController alloc] init];
	directionViewcontroller.tabBarViewController = tabBarView;
	appointmentViewController = [[AppointmentViewController alloc] init];
	appointmentViewController.tabBarViewController = tabBarView;
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[homeViewController release];
	[directionViewcontroller release];
	[appointmentViewController release];
	[tabBarView release];
	[navigationController release];
    [super dealloc];
}


@end
